define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		//品牌一览
		function get_data_brands(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"brand":[{"id":"001","name":"世达"},{"id":"002","name":"博士"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};

	    //商品数据
        function get_data_goods_search(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"goods": [' +
                    '{"goods_id": 1,"name": "螺丝刀","bn": "新品","store": 100,"price": 10.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 1,"image_default": "img/upload/pro-img01.jpg","freez": 10,"is_tui": true,"is_new": true},' +
                    '{"goods_id": 2,"name": "螺丝刀","bn": "热卖","store": 1001,"price": 11.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 2,"image_default": "img/upload/pro-img01.jpg","freez": 15,"is_tui": true,"is_new": false}]},' +
                    '"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        };

		//返回信息
		return {
			//品牌一览
			brands: function(callback) {
				Http.post({
					method: 'goods.brand.getlist',
				}, function(result) {
                    if(callback)
                    	callback(get_data_brands(result).result);
				}, function(e) {

				}, function() {

				})
			},
		    //商品数据
		    goods_search: function(key, nPage, orderby, filter, marketable, callback, calldone) {
                Http.post({
                    method: 'goods.insales.search',
                    key:key,
                    nPage: nPage,
                    pagelimit:10,
                     orderby: orderby,
                    filter:filter,//商品检索的条件
                    marketable:marketable
                }, function(result) {
                    if(callback)
                    	callback(get_data_goods_search(result).result);
                }, function(e) {

                }, function() {
					if(calldone)
						calldone();
            	})
            },
            //上下架
            goods_update:function(goods_id,marketable,callback){
                Http.post({
                    method:'goods.marketable.update',
                    goods_id:goods_id,
                    marketable:marketable//上、下架
                },function(result){
                    if(callback)
                        callback(result);
                },function(e){

                },function(){

                })
            },
            //删除商品
            goods_delete:function(goods_id,callback){
                Http.post({
                    method:'goods.goods.delete',
                    goods_id:goods_id
                },function(result){
                    if(callback)
                        callback(result);
                },function(e){

                },function(){

                })
            },
            //添加商品标签
            addGoodsTag:function(goods_id_list,tag_id_list,callback){
                Http.post({
                    method:'shop.do_edittag',
                    goods_id_list:goods_id_list,
                    tag_id_list:tag_id_list
                },function(result){
                    if(callback)
                        callback(result);
                },function(e){

                },function(){

                })
            },
            //获取商品标签一览
            getTagList:function(callback){
                Http.post({
                    method:'goods.get_tag',
                },function(result){
                    if(callback)
                        callback(result);
                },function(e){

                },function(){

                })
            }

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Productmanager", factory);
});